package com.liuyang.demo.time;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.FastDateFormat;

import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;

public class TimeConvert {
    public static void main(String[] args) {
        printTime();
        //dateTest();
        System.out.println(ZoneId.systemDefault());
        Date minTime1 = Date.from(LocalDate.now().atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
        System.out.println(minTime1);
        Date minTime = Date.from(LocalDate.now().minusDays(90 - 1).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
        System.out.println(minTime);

    }

    public static void dateTest(){
        Date today = new Date();
        Date beginOfToday = DateUtil.beginOfDay(today).toJdkDate();
        Date endOfToday = DateUtil.endOfDay(today).toJdkDate();
        System.out.println(today);
        System.out.println(beginOfToday);
        System.out.println(endOfToday);
    }

    public static void beginOfTodayTest(){
        DateTime today = new DateTime();
        Date beginOfToday = DateUtil.beginOfDay(today);
        Date endOfToday = DateUtil.endOfDay(today);
        System.out.println(today);
        System.out.println(beginOfToday);
        System.out.println(endOfToday);
    }

    public static void printTime(){
        String time = "1618971695000";
        String format = DateFormatUtils.format(Long.parseLong(time), "yyyy-MM-dd HH:mm:ss");
        System.out.println(format);
    }

}
